﻿#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <string>


//完全数计算
//https://www.nowcoder.com/questionTerminal/7299c12e6abb437c87ad3e712383ff84?orderByHotValue=0&commentTags=Java
//int main()
//{
//	int num = 0;
//	while (cin >> num)
//	{
//		int flag = 0;
//		for (int k = 1; k < num; ++k)
//		{
//			int sum = 0;
//			for (int i = 1; i < (k - k / 3); ++i)
//			{
//				if (k % i == 0) { sum += i; }
//			}
//			if (k == sum) { ++flag; }
//		}
//		cout << flag << endl;
//	}
//	return 0;
//}

//扑克牌大小 - 暴力破解
//https://www.nowcoder.com/questionTerminal/d290db02bacc4c40965ac31d16b1c3eb?orderByHotValue=0&commentTags=Java
int numcards(const char x) {
    switch (x) {
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    case '1':
        return 10;
    case 'J':
        return 11;
    case 'Q':
        return 12;
    case 'K':
        return 13;
    case 'A':
        return 14;
    case '2':
        return 15;
    }
    return 0;
}

size_t spacesum(const string& s) {
    int sum = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == ' ') {
            ++sum;
        }
    }
    return sum;
}

int main() {
    string str;
    while (getline(cin, str)) {
        size_t sub = str.find('-');
        string s1(str.c_str(), str.c_str() + sub);
        string s2(str.c_str() + (sub + 1), str.c_str() + str.size());

        size_t s1_size = spacesum(s1);
        size_t s2_size = spacesum(s2);

        //对比对王
        bool s1_king = s1.find("JOKER") != string::npos ? true : false;
        bool s1_surname = s1.find("joker") != string::npos ? true : false;
        bool s2_king = s2.find("JOKER") != string::npos ? true : false;
        bool s2_surname = s2.find("joker") != string::npos ? true : false;
        if ((s1_king && s1_surname) || (s2_king && s2_surname)) {
            cout << "joker JOKER" << endl;
            continue;
        }
        else if (s1_king && s2.size() == 1 || s2_king && s1.size() == 1) {
            cout << "JOKER" << endl;
            continue;
        }
        else if (s1_surname && s2.size() == 1 || s2_surname && s1.size() == 1) {
            cout << "joker" << endl;
            continue;
        }

        //对比炸弹
        if (s1_size == 3 && s2_size == 3) {
            if (numcards(s1[0]) > numcards(s2[0])) {
                cout << s1 << endl;
            }
            else {
                cout << s2 << endl;
            }
            continue;
        }
        else if (s1_size == 3) {
            cout << s1 << endl;
            continue;
        }
        else if (s2_size == 3) {
            cout << s2 << endl;
            continue;
        }

        //对比顺子
        if (s1_size == 4 && s2_size == 4) {
            if (numcards(s1[0]) > numcards(s2[0])) {
                cout << s1 << endl;
            }
            else {
                cout << s2 << endl;
            }
            continue;
        }
        else if (s1_size == 4 && s2_size != 4 || s1_size != 4 && s2_size == 4) {
            cout << "ERROR" << endl;
            continue;
        }

        //对比三张
        if (s1_size == 2 && s2_size == 2) {
            if (numcards(s1[0]) > numcards(s2[0])) {
                cout << s1 << endl;
            }
            else {
                cout << s2 << endl;
            }
            continue;
        }
        else if (s1_size == 2 && s2_size != 2 || s1_size != 2 && s2_size == 2) {
            cout << "ERROR" << endl;
            continue;
        }

        //对比对子
        if (s1_size == 1 && s2_size == 1) {
            if (numcards(s1[0]) > numcards(s2[0])) {
                cout << s1 << endl;
            }
            else {
                cout << s2 << endl;
            }
            continue;
        }
        else if (s1_size == 1 && s2_size != 1 || s1_size != 1 && s1_size == 1) {
            cout << "ERROR" << endl;
            continue;
        }

        //对比单张
        //处理大小王问题
        if (s1_king || s2_king) {
            cout << "JOKER" << endl;
        }
        else if (s1_surname || s2_surname) {
            cout << "joker" << endl;
        }
        else {
            if (s1_size == 0 && s2_size == 0) {
                if (numcards(s1[0]) > numcards(s2[0])) {
                    cout << s1 << endl;
                }
                else {
                    cout << s2 << endl;
                }
            }
            else {
                cout << "ERROR" << endl;
                continue;
            }
        }

    }
}